package com.ruoyi.classscoreonmonth.controller;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.classscoreonmonth.domain.StrengthsWeaknesses;
import com.ruoyi.classscoreonmonth.domain.vo.SelectTemp;
import com.ruoyi.classscoreonmonth.domain.vo.TermDate;
import com.ruoyi.classscoreonmonth.service.ISStrengthsWeaknesses;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.count.domain.StrengthWeaknessTmp;
import com.ruoyi.count.domain.Studentstandardscores;
import com.ruoyi.count.domain.vo.StrengWeakContent;
import com.ruoyi.count.domain.vo.StrengthWeakDate1;
import com.ruoyi.count.service.IStudentstandardscoresService;
import com.ruoyi.teacher.domain.Teacher;
import com.ruoyi.teacher.mapper.TeacherMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * @author 尹欣雨
 * @verdion 520
 * 22:38
 */
@RestController
@RequestMapping("/StrengthsWeaknesses/StrengthsWeaknesses")
public class StrengthsWeaknessesController {
    @Autowired
    private IStudentstandardscoresService studentstandardscoresService;
    @Autowired
    private ISStrengthsWeaknesses isStrengthsWeaknesses;
    @Autowired
    private TeacherMapper teacherMapper;

    /**
     * 根据学校 年级 班级 评价时间 获取学生成绩
     * 进行学生强弱项分析 存进数据库
     * 这部分进行数据处理
     */
    @Anonymous
    @GetMapping("/gen")
    public AjaxResult getStrengthsWeaknesses(SelectTemp selectTemp) {
        // 构造查询条件
        Studentstandardscores studentstandardscores = new Studentstandardscores();
        studentstandardscores.setSchool(selectTemp.getSchoolName());
        studentstandardscores.setGrade(selectTemp.getYearAdmission());
        studentstandardscores.setClasss(selectTemp.getClassName());
        String yearTerm = selectTemp.getYearTerm();
        System.out.println(yearTerm);
        TermDate termDate = getTermDates(Integer.parseInt(selectTemp.getYearAdmission()), yearTerm);
        // 拿到符合条件的学生的每个月的成绩
        List<Studentstandardscores> list = studentstandardscoresService.selectStudentstandardscoresList(studentstandardscores);
        String startDate = termDate.getStartDate();
        String endDate = termDate.getEndDate();
        List<Studentstandardscores> listBefore1 = list.stream()
                .filter(element -> {
                    // 获取计算时间的年月部分
                    String calcYearMonth = getYearMonthFromDate(element.getCalculationtime());
                    // 比较日期字符串
                    return calcYearMonth.compareTo(startDate) >= 0 && calcYearMonth.compareTo(endDate) <= 0;
                })
                .collect(Collectors.toList());
        // 处理信息
        List<StrengthWeaknessTmp> List1 = getStrengthWeaknessTmps(listBefore1);
        List<StrengthWeakDate1> DateList = calculateAverageScores(List1);
        // 获取全部的年纪信息
        List<StrengthWeaknessTmp> AllGradeList = AllGradeList(selectTemp.getSchoolName(), selectTemp.getYearAdmission());
        List<StrengthWeakDate1> AllGradeListDate = calculateAverageScores(AllGradeList);
        List<StrengWeakContent> weak = getWeakness(DateList, AllGradeListDate);
        List<StrengWeakContent> Strength = getStrength(DateList, AllGradeListDate);
        List<StrengthsWeaknesses> strengthsWeaknesseslist = insertStrengthWeakContent(studentstandardscores, weak, Strength);
        System.out.println(strengthsWeaknesseslist);
        return AjaxResult.success(strengthsWeaknesseslist);
    }

    // 提取年月部分的方法
    private static String getYearMonthFromDate(Date date) {
        SimpleDateFormat yearMonthFormatter = new SimpleDateFormat("yyyy-MM");
        return yearMonthFormatter.format(date);
    }

    /**
     * 拿取这个学期的start -end月份
     */

    public static TermDate getTermDates(int startYear, String gradeTerm) {
        // 解析学年和学期
        Pattern pattern = Pattern.compile("(\\d+)年级(上学期|下学期)");
        Matcher matcher = pattern.matcher(gradeTerm);

        if (!matcher.find()) {
            return null; // 格式错误
        }

        int grade = Integer.parseInt(matcher.group(1)); // 获取年级
        String term = matcher.group(2); // 获取学期（上学期或下学期）

        // 根据入学年份和年级推算当前学年的年份
        int schoolYear = startYear + grade - 1; // 学年从入学年份开始

        int startMonth, endMonth;

        // 根据学期推算起始和结束月份
        if ("上学期".equals(term)) {
            // 上学期：从 9月 到 1月
            startMonth = 9;
            endMonth = 1; // 上学期通常到第二年1月结束
        } else if ("下学期".equals(term)) {
            // 下学期：从 3月 到 6月
            startMonth = 3;
            endMonth = 6;
        } else {
            return null; // 未知学期
        }

        int startDateYear = startMonth == 9 ? schoolYear : schoolYear + 1; // 上学期年份不变，下学期年份加 1
        int endDateYear = endMonth == 1 ? schoolYear + 1 : schoolYear; // 上学期结束在第二年，下学期保持当前年份

        // 拼接日期，确保月份为两位数
        String startDate = String.format("%d-%02d", startDateYear, startMonth);
        String endDate = String.format("%d-%02d", endDateYear, endMonth);

        return new TermDate(startDate, endDate);
    }

    ;

    /**
     * 强弱项语句插入数据库
     */

    private List<StrengthsWeaknesses> insertStrengthWeakContent(Studentstandardscores studentstandardscores, List<StrengWeakContent> list1, List<StrengWeakContent> list2) {
        List<StrengthsWeaknesses> strengthsWeaknesseslist = new ArrayList<>();
        list1.forEach(item -> {
            String studentId = item.getStudentId();
            String weakness = item.getResult();
            String Strengths = list2.stream()
                    .filter(element -> element.getStudentId().equals(studentId)) // 筛选学号匹配的元素
                    .findFirst().get().getResult();
            StrengthsWeaknesses strengthsWeaknesses = new StrengthsWeaknesses();
            strengthsWeaknesses.setStudentId(studentId);
            strengthsWeaknesses.setYearTime(studentstandardscores.getGrade());
            strengthsWeaknesses.setClassName(studentstandardscores.getClasss());
            strengthsWeaknesses.setSchoolName(studentstandardscores.getSchool());
            strengthsWeaknesses.setWeaknesses(HabdleDate(weakness, 1).toString());
            strengthsWeaknesses.setStrengths(HabdleDate(Strengths, 2).toString());
            strengthsWeaknesseslist.add(strengthsWeaknesses);
        });
        return strengthsWeaknesseslist;
    }

    /**
     * 处理数据
     */

    private static StringBuilder HabdleDate(String oldDate, int type) {
        StringBuilder result = new StringBuilder();
        if (type == 1) {
            // 使用正则表达式提取等号前面的值
            Pattern pattern = Pattern.compile("([^,=]+)=(\\d+\\.\\d+)");
            Matcher matcher = pattern.matcher(oldDate);
            // 遍历所有匹配项，提取等号左边的值
            while (matcher.find()) {
                String leftValue = matcher.group(1); // 获取等号左边的值
                result.append(leftValue).append(", "); // 拼接结果
            }
            // 删除最后一个多余的 ", "（如果有的话）
            if (result.length()!=0) {
                result.setLength(result.length() - 2); // 删除最后的 ", "
            }
        } else if (type == 2) {
            // 去除大括号并分割每个键值对
            String cleanedInput = oldDate.substring(1, oldDate.length() - 1); // 去掉前后的大括号
            String[] keyValuePairs = cleanedInput.split(",\\s*");  // 按逗号分割，并去掉可能的空格
            // 提取每个键值对的等号前的部分
            for (String pair : keyValuePairs) {
                String[] parts = pair.split("="); // 按等号分割
                if (parts.length == 2) {
                    String leftValue = parts[0].trim();  // 获取等号前面的部分
                    result.append(leftValue).append(" ");  // 将提取的值追加到结果字符串
                }
            }
        }
        return result;
    }

    /**
     * 强项分析
     */

    public static List<StrengWeakContent> getStrength(List<StrengthWeakDate1> list, List<StrengthWeakDate1> allGradeList) {
        // 定义一个存储所有学生强项的集合
        Map<String, Map<String, String>> studentStrengths = new HashMap<>();

        // 遍历所有学生
        for (StrengthWeakDate1 student : list) {
            String studentId = student.getStudentId();  // 假设每个学生有一个唯一的 ID
            Map<String, Integer> studentScores = student.getScore();  // 获取学生的得分
            // System.out.println(studentScores);
            int totalIndicator = studentScores.get("totalIndicator");  // 获取学生的总指标分数，默认0

            // 定义学生的强项指标
            Map<String, String> firstLevelStrengths = new HashMap<>();
            Map<String, String> secondLevelStrengths = new HashMap<>();
            Map<String, String> thirdLevelStrengths = new HashMap<>();

            // 强项分析：一级指标
            Map<String, Integer> firstLevelStrengthsTemp = new HashMap<>();
            for (StrengthWeakDate1 gradeStudent : allGradeList) {
                Map<String, Integer> allScores = gradeStudent.getScore();  // 所有学生的得分

                // 遍历所有得分，检查一级指标
                for (Map.Entry<String, Integer> entry : allScores.entrySet()) {
                    String key = entry.getKey();
                    int score = entry.getValue();

                    if (key.split("\\.").length == 1) {  // 判断一级指标
                        firstLevelStrengthsTemp.put(key, firstLevelStrengthsTemp.getOrDefault(key, 0) + score);
                    }
                }
            }

            // 分析一级指标的强项
            for (Map.Entry<String, Integer> entry : firstLevelStrengthsTemp.entrySet()) {
                String firstLevelId = entry.getKey();
                int total = entry.getValue();
                int averageScore = total / allGradeList.size();  // 平均分
                int studentScore = studentScores.getOrDefault(firstLevelId, 0);
                // System.out.println("学号 : " + studentId);
                // System.out.println("总分：" + totalIndicator + ", 平均分：" + averageScore + ", 学生得分：" + studentScore);
                // 判断强项的条件
                if ((totalIndicator == 7 || totalIndicator == 8) && studentScore > averageScore) {
                    firstLevelStrengths.put(firstLevelId, String.valueOf(studentScore));
                } else if (totalIndicator >= 2 && totalIndicator <= 6 && (studentScore == 7 || studentScore == 8)) {
                    firstLevelStrengths.put(firstLevelId, String.valueOf(studentScore));
                }
            }

            // 强项分析：二级和三级指标
            Map<String, Integer> secondLevelStrengthsTemp = new HashMap<>();
            Map<String, Integer> thirdLevelStrengthsTemp = new HashMap<>();

            for (StrengthWeakDate1 gradeStudent : allGradeList) {
                Map<String, Integer> allScores = gradeStudent.getScore();

                for (Map.Entry<String, Integer> entry : allScores.entrySet()) {
                    String key = entry.getKey();
                    int score = entry.getValue();

                    if (key.split("\\.").length == 2) {  // 判断二级指标
                        secondLevelStrengthsTemp.put(key, secondLevelStrengthsTemp.getOrDefault(key, 0) + score);
                    }
                    if (key.split("\\.").length == 3) {  // 判断三级指标
                        thirdLevelStrengthsTemp.put(key, thirdLevelStrengthsTemp.getOrDefault(key, 0) + score);
                    }
                }
            }

            // 分析二级指标的强项
            for (Map.Entry<String, Integer> entry : secondLevelStrengthsTemp.entrySet()) {
                String secondLevelId = entry.getKey();
                int total = entry.getValue();
                int averageScore = total / allGradeList.size();  // 平均分
                int studentScore = studentScores.getOrDefault(secondLevelId, 0);

                // 判断强项的条件
                if ((totalIndicator == 7 || totalIndicator == 8) && studentScore > averageScore) {
                    secondLevelStrengths.put(secondLevelId, String.valueOf(studentScore));
                } else if (totalIndicator >= 2 && totalIndicator <= 6 && (studentScore == 7 || studentScore == 8)) {
                    secondLevelStrengths.put(secondLevelId, String.valueOf(studentScore));
                }
            }

            // 分析三级指标的强项
            for (Map.Entry<String, Integer> entry : thirdLevelStrengthsTemp.entrySet()) {
                String thirdLevelId = entry.getKey();
                int total = entry.getValue();
                int averageScore = total / allGradeList.size();  // 平均分
                int studentScore = studentScores.getOrDefault(thirdLevelId, 0);

                // 判断强项的条件
                if ((totalIndicator == 7 || totalIndicator == 8) && studentScore > averageScore) {
                    thirdLevelStrengths.put(thirdLevelId, String.valueOf(studentScore));
                } else if (totalIndicator >= 2 && totalIndicator <= 6 && (studentScore == 7 || studentScore == 8)) {
                    thirdLevelStrengths.put(thirdLevelId, String.valueOf(studentScore));
                }
            }

            // 将学生的强项存储起来
            Map<String, String> studentOverallStrengths = new HashMap<>();
            studentOverallStrengths.putAll(firstLevelStrengths);
            studentOverallStrengths.putAll(secondLevelStrengths);
            studentOverallStrengths.putAll(thirdLevelStrengths);

            studentStrengths.put(studentId, studentOverallStrengths);
        }

        // 输出每个学生的强项
        List<StrengWeakContent> date = new ArrayList<>();
        for (Map.Entry<String, Map<String, String>> entry : studentStrengths.entrySet()) {
            String studentId = entry.getKey();
            Map<String, String> studentStrength = entry.getValue();
            // System.out.println("学生ID: " + studentId + " 强项: " + studentStrength);
            StrengWeakContent result = new StrengWeakContent();
            result.setStudentId(studentId);
            result.setResult(studentStrength.toString());
            date.add(result);
        }
        return date;
    }

    /**
     * 分项弱项
     */

    private static List<StrengWeakContent> getWeakness(List<StrengthWeakDate1> list, List<StrengthWeakDate1> AllGradeList) {
        Map<Integer, Map<String, String>> weaknesses = new HashMap<>();

        for (StrengthWeakDate1 targetStudent : list) {
            int targetTotalScore = targetStudent.getScore().get("totalIndicator");

            // 1. 找到年级中与目标学生总分相同的学生（用于一级指标分析）
            List<StrengthWeakDate1> relevantStudents = AllGradeList.stream()
                    .filter(student -> student.getScore().get("totalIndicator") == targetTotalScore)
                    .collect(Collectors.toList());

            // 2. 一级指标分析
            Set<String> firstLevelKeys = getKeysByLevel(targetStudent.getScore(), 1);
            Map<String, String> firstLevelWeaknesses = new HashMap<>();

            // 遍历每个一级指标，计算它在总分相同的学生中的平均值
            for (String firstLevelKey : firstLevelKeys) {
                double firstLevelAverage = calculateAverageScore(relevantStudents, firstLevelKey);
                if (targetStudent.getScore().getOrDefault(firstLevelKey, 0) < firstLevelAverage) {
                    firstLevelWeaknesses.put(firstLevelKey, String.format("%.2f", firstLevelAverage));
                }
            }

            // 3. 二级和三级指标分析（基于一级指标分数相同的学生）
            Map<String, String> secondAndThirdLevelWeaknesses = new HashMap<>();
            for (String firstLevelKey : firstLevelKeys) {
                // 获取与目标学生一级指标分数相同的学生
                List<StrengthWeakDate1> studentsWithSameFirstLevelScore = AllGradeList.stream()
                        .filter(student -> student.getScore().getOrDefault(firstLevelKey, 0)
                                == targetStudent.getScore().getOrDefault(firstLevelKey, 0))
                        .collect(Collectors.toList());

                // 3.1 二级指标分析
                Set<String> secondLevelKeys = getKeysByPrefix(targetStudent.getScore(), firstLevelKey + ".");
                for (String secondLevelKey : secondLevelKeys) {
                    double secondLevelAverage = calculateAverageScore(studentsWithSameFirstLevelScore, secondLevelKey);
                    if (targetStudent.getScore().getOrDefault(secondLevelKey, 0) < secondLevelAverage) {
                        secondAndThirdLevelWeaknesses.put(secondLevelKey, String.format("%.2f", secondLevelAverage));
                    }

                    // 3.2 三级指标分析
                    Set<String> thirdLevelKeys = getKeysByPrefix(targetStudent.getScore(), secondLevelKey + ".");
                    for (String thirdLevelKey : thirdLevelKeys) {
                        double thirdLevelAverage = calculateAverageScore(studentsWithSameFirstLevelScore, thirdLevelKey);
                        if (targetStudent.getScore().getOrDefault(thirdLevelKey, 0) < thirdLevelAverage) {
                            secondAndThirdLevelWeaknesses.put(thirdLevelKey, String.format("%.2f", thirdLevelAverage));
                        }
                    }
                }
            }

            // 存储分析结果
            weaknesses.put(Integer.valueOf(targetStudent.getStudentId()), Map.of(
                    "firstLevel", firstLevelWeaknesses.toString(),
                    "secondAndThirdLevel", secondAndThirdLevelWeaknesses.toString()
            ));
        }

        List<StrengWeakContent> content = new ArrayList<>();

        // 遍历weaknesses，将分析结果填充到StrengWeakContent对象中
        weaknesses.forEach((studentId, result) -> {
            StrengWeakContent temp = new StrengWeakContent();
            temp.setStudentId(String.valueOf(studentId));

            // 处理一级薄弱项
            String firstLevelWeaknessStr = result.get("firstLevel");
            List<String> firstWeakness = parseWeakness(firstLevelWeaknessStr); // 解析一级薄弱项
            // 处理二级和三级薄弱项
            String secondAndThirdLevelWeaknessStr = result.get("secondAndThirdLevel");
            List<String> secondAndThirdWeakness = parseWeakness(secondAndThirdLevelWeaknessStr); // 解析二级和三级薄弱项

            // System.out.println("Student ID: " + studentId);
            // System.out.println("一级薄弱项: " + firstWeakness);
            // System.out.println("二级和三级薄弱项: " + secondAndThirdWeakness);
            StringBuilder s = new StringBuilder();
            firstWeakness.forEach(item -> {
                s.append(item).append(",");
            });
            secondAndThirdWeakness.forEach(item -> {
                s.append(item).append(",");
            });
            // 移除最后一个多余的逗号
            if (s.length() > 0) {
                s.deleteCharAt(s.length() - 1);
            }
            // System.out.println(s);
            temp.setResult(String.valueOf(s));
            content.add(temp);
        });
        return content;
        // System.out.println(content);
    }

    /**
     * 假设parseWeakness方法用于将"一级薄弱项"的字符串解析为List
     *
     * @param weaknessStr
     * @return
     */
    private static List<String> parseWeakness(String weaknessStr) {
        // 如果为空或者无内容，返回空列表
        if (weaknessStr == null || weaknessStr.isEmpty()) {
            return new ArrayList<>();
        }
        // 去掉大括号并按逗号分隔，返回指标名称列表
        String[] weaknesses = weaknessStr.replaceAll("[{}]", "").split(",");
        return Arrays.asList(weaknesses);
    }

    /**
     * 计算某个指标在学生列表中的平均分
     *
     * @param students
     * @param key
     * @return
     */
    private static double calculateAverageScore(List<StrengthWeakDate1> students, String key) {
        return students.stream()
                .mapToInt(student -> student.getScore().getOrDefault(key, 0))
                .average()
                .orElse(0);
    }

    /**
     * 动态提取指定层级的指标键
     */
    private static Set<String> getKeysByLevel(Map<String, Integer> scoreMap, int level) {
        Set<String> keys = new HashSet<>();
        for (String key : scoreMap.keySet()) {
            if (key.matches("^\\d+(\\.\\d+){0," + (level - 1) + "}$")) { // 匹配层级
                keys.add(key);
            }
        }
        return keys;
    }

    /**
     * 动态提取指定前缀的指标键
     */
    private static Set<String> getKeysByPrefix(Map<String, Integer> scoreMap, String prefix) {
        return scoreMap.keySet().stream()
                .filter(key -> key.startsWith(prefix) && key.split("\\.").length == prefix.split("\\.").length + 1)
                .collect(Collectors.toSet());
    }

    /**
     * 提取部分信息
     *
     * @param list
     * @return
     */
    private static List<StrengthWeaknessTmp> getStrengthWeaknessTmps(List<Studentstandardscores> list) {
        List<StrengthWeaknessTmp> List1 = new ArrayList<>();
        for (Studentstandardscores item : list) {
            StrengthWeaknessTmp tmp = new StrengthWeaknessTmp();
            Date calculationtime = new Date(String.valueOf(item.getCalculationtime()));
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
            String formattedDate = sdf.format(calculationtime);
            tmp.setStudentId(item.getStudentId());
            tmp.setCalculationtime(formattedDate);
            tmp.setScore(item.getStrandScore());
            List1.add(tmp);
        }
        return List1;
    }

    /**
     * 解析 score 字符串为 Map<String, Integer>
     *
     * @param scoreJson
     * @return
     */
    private static Map<String, Integer> parseScore(String scoreJson) {
        // System.out.println(scoreJson);
        Map<String, Integer> resultMap = new HashMap<>();
        JSONObject jsonObject = JSONObject.parseObject(scoreJson);
        for (String key : jsonObject.keySet()) {
            resultMap.put(key, jsonObject.getInteger(key));
        }
        return resultMap;
    }

    /**
     * 拿取整个年级的数据
     */
    private List<StrengthWeaknessTmp> AllGradeList(String school, String grade) {
        // 构造查询条件
        Studentstandardscores studentstandardscores = new Studentstandardscores();
        studentstandardscores.setSchool(school);
        studentstandardscores.setGrade(grade);
        // 拿到符合条件的学生的每个月的成绩
        List<Studentstandardscores> list = studentstandardscoresService.selectStudentstandardscoresList(studentstandardscores);
        return getStrengthWeaknessTmps(list);
    }

    /**
     * 计算每个学生的平均分
     */
    private static List<StrengthWeakDate1> calculateAverageScores(List<StrengthWeaknessTmp> List1) {
        // 按学号分组 求学生几个月的平均成绩
        Map<String, List<StrengthWeaknessTmp>> studentMap = new HashMap<>();
        List<StrengthWeakDate1> DateList = new ArrayList<>();
        for (StrengthWeaknessTmp item : List1) {
            studentMap.computeIfAbsent(item.getStudentId(), k -> new ArrayList<>()).add(item);
        }

        // 计算每个学号每个指标的平均值
        for (Map.Entry<String, List<StrengthWeaknessTmp>> entry : studentMap.entrySet()) {
            String studentId = entry.getKey();
            List<StrengthWeaknessTmp> studentRecords = entry.getValue();

            // 用于存储每个指标的总和及出现次数
            Map<String, Double> sumMap = new HashMap<>();
            Map<String, Integer> countMap = new HashMap<>();

            // 遍历该学生的每条记录，累加每个指标的值
            for (StrengthWeaknessTmp record : studentRecords) {
                Map<String, Integer> indicators = parseScore(record.getScore()); // 解析字符串到Map
                for (Map.Entry<String, Integer> indicator : indicators.entrySet()) {
                    String key = indicator.getKey();
                    double value = indicator.getValue();

                    // 更新总和和计数
                    sumMap.put(key, sumMap.getOrDefault(key, 0.0) + value);
                    countMap.put(key, countMap.getOrDefault(key, 0) + 1);
                }
            }

            // 输出每个学号每个指标的平均值
            // System.out.println("学号: " + studentId);
            StrengthWeakDate1 strengthWeakDate1 = new StrengthWeakDate1();
            strengthWeakDate1.setStudentId(studentId);
            Map<String, Integer> indicatorIndexMap = new HashMap<>();
            for (Map.Entry<String, Double> sumEntry : sumMap.entrySet()) {
                String indicator = sumEntry.getKey();
                double totalSum = sumEntry.getValue();
                int count = countMap.get(indicator);
                int average = (int) Math.round(totalSum / count);
                // System.out.println("指标: " + indicator + ", 平均值: " + average);
                indicatorIndexMap.put(indicator, average);
            }
            strengthWeakDate1.setScore(indicatorIndexMap);
            DateList.add(strengthWeakDate1);
        }
        return DateList;
    }

    /***
     * 拿取评价信息
     */
    @Anonymous
    @GetMapping(value = "/genList/{username}/{time}")
    public AjaxResult getStrengthsWeaknessesList(@PathVariable("username") String username, @PathVariable("time") String CommentTime) {

        Teacher teacher = new Teacher();
        teacher.setTeacherid(username);
        List<Teacher> teacher1 = teacherMapper.selectTeacherList(teacher);
        String classs = teacher1.get(0).getClassss();
        String grade = teacher1.get(0).getGrade();
        String school = teacher1.get(0).getSchool();


        StrengthsWeaknesses strengthsWeaknesses = new StrengthsWeaknesses();
        strengthsWeaknesses.setYearTime(grade);
        strengthsWeaknesses.setSchoolName(school);
        strengthsWeaknesses.setClassName(classs);
        strengthsWeaknesses.setCommentTime(CommentTime);

        return AjaxResult.success(isStrengthsWeaknesses.selectStrengthsWeaknessesList(strengthsWeaknesses));
    }
}
